package com.topvision.controller.face;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.topvision.model.glass.FaceAlarm;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topvision.service.face.FaceAlarmService;
import com.topvision.util.PageUtils;
import com.topvision.util.Query;
import com.topvision.util.R;
import com.topvision.controller.AbstractController;

/**
 * 报警信息
 *
 * @author shengwm
 * @email 179653076@qq.com
 * @date 2018-03-12 15:51:35
 */
@RestController
@RequestMapping("face/facealarm")
public class FaceAlarmController extends AbstractController {
    @Autowired
    private FaceAlarmService faceAlarmService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("face/facealarm:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<FaceAlarm> faceAlarmList = faceAlarmService.queryList(query);
        int total = faceAlarmService.queryTotal(query);
//        ArrayList<FaceAlarm> resultFaceAlarmList = new ArrayList<>();
//        for (FaceAlarm faceAlarm : faceAlarmList) {
//            String snapBase64Data = "data:image/jpg;base64," + faceAlarm.getSnapBase64Data();
//            String faceBase64Data = "data:image/jpg;base64," + faceAlarm.getFaceBase64Data();
//            System.out.println(snapBase64Data);
//            faceAlarm.setSnapBase64Data(snapBase64Data);
//            faceAlarm.setFaceBase64Data(faceBase64Data);
//            resultFaceAlarmList.add(faceAlarm);
//        }
        PageUtils pageUtil = new PageUtils(faceAlarmList, total, query.getLimit(), query.getPage());

        return R.success().put("page", pageUtil);
    }

    @RequestMapping("/findListByParam")
    @RequiresPermissions("face/facealarm:list")
    public R findListByParam(@RequestParam Map<String, Object> params) {

        List<FaceAlarm> faceAlarmList = faceAlarmService.queryByParam(params);

        return R.success().put("faceAlarmList", faceAlarmList);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("face/facealarm:info")
    public R info(@PathVariable("id") Integer id) {
        FaceAlarm faceAlarm = faceAlarmService.queryObject(id);
        return R.success().put("faceAlarm", faceAlarm);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("face/facealarm:save")
    public R save(@RequestBody FaceAlarm faceAlarm) {
        faceAlarmService.save(faceAlarm);
        return R.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("face/facealarm:update")
    public R update(@RequestBody FaceAlarm faceAlarm) {
        faceAlarmService.update(faceAlarm);
        return R.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("face/facealarm:delete")
    public R delete(@RequestBody Integer[] ids) {
        faceAlarmService.deleteBatch(ids);
        return R.success();
    }

}
